﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReBasic.Database;

namespace ReBasic.Model
{
    public class Triple_hrt:IComparable<Triple_hrt>

    {
        public string host_entity, relation, target_entity;
        public int fhrt, fhr, fht, frt, blank_int;
        public string occPos, blank_string;
        public double q, qhrt, pct, blank_double;

        public Triple_hrt() { }

        public Triple_hrt(Quad_hrtT quad, string attr)
        { 
            host_entity = ProBase.SubUhash[quad.h_idx];
            target_entity = ProBase.SubUhash[quad.t_idx];
            relation = attr;
            fhrt = quad.freq;
            q = quad.qq;
            occPos = quad.occPos;
        }

        public Triple_hrt(string a, string b, string c, int hrt, int hr, int ht, int rt, string op)
        {
            host_entity = a;
            relation = b;
            target_entity = c;
            fhrt = hrt;
            fhr = hr;
            fht = ht;
            frt = rt;
            occPos = op;
        }

        public Triple_hrt(Triple_hrt tp)
        { 
            this.host_entity = tp.host_entity;
            this.relation = tp.relation;
            this.target_entity = tp.target_entity;
            this.fhrt = tp.fhrt;
            this.fhr = tp.fhr;
            this.fht = tp.fht;
            this.frt = tp.frt;
            this.q = tp.q;
            this.occPos = tp.occPos;
        }

        public void CalcQ()
        {
            if (fhrt == 0) q = 0;
            //q = 1.0 * fhrt / fhr * fhrt / frt;          //remove q(r|h,t) because it's too noisy.
            //q = 1.0 * fhrt / fhr * fhrt / fht * fhrt / frt;
            q = (1.0 * fhrt / fhr * fhrt / fht * fhrt / frt) * (1 + Math.Log(fhrt, 10));
        }

        #region IComparable<Triple_hrt> 成员

        public int CompareTo(Triple_hrt other)
        {
            return -(q.CompareTo(other.q));
        }

        #endregion
    }
}
